SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE dbo.[DnnProduct_CDS_TemplateAddStamp]
	@DistributorID varchar(50),
	@TemplateID int,
	@DefaultStampConfigID int,
	@DRMType varchar(20)
AS
BEGIN
	IF (coalesce(@DRMType, 'Stamp') = 'Stamp')
		INSERT INTO [DnnProduct_CDS_StampSets] (TemplateID, DefaultStampConfigID)
		SELECT T.ID, SC.ID FROM [DnnProduct_CDS_Templates] T
		INNER JOIN [DISC_DefaultStampConfig] SC ON SC.ID = @DefaultStampConfigID AND SC.distID = @DistributorID
		WHERE T.ID = @TemplateID AND T.DistributorID = @DistributorID
	ELSE
		INSERT INTO [DnnProduct_CDS_StampSets] (TemplateID, DefaultDRMStampConfigID)
		SELECT T.ID, SC.ID FROM [DnnProduct_CDS_Templates] T
		INNER JOIN [DISC_DefaultDRMStampConfig] SC ON SC.ID = @DefaultStampConfigID AND SC.distID = @DistributorID
		WHERE T.ID = @TemplateID AND T.DistributorID = @DistributorID
	
	SELECT scope_identity()
END
GO
